import {Injectable} from '@angular/core';
import {NHttpClinet} from '@core/utils/http.client';
import {TableFiled} from '@core/interfaces/table.interface';
import {BaseService} from '@core/utils/BaseRequest';
import {ResponseModel} from "@core/utils/ResponseModel";


@Injectable()
export class QuestionListService extends BaseService {

  constructor(http: NHttpClinet) {
    super('question', http);
  }

  /**
   * 获取列表表头
   * @returns {TableFiled[]}
   */
  getTableHeader(): TableFiled[] {
    return [
      {
        field: 'qid',
        text: '题目ID',
        isHidden: true
      },
      {
        field: 'type',
        text: '问题类别',
        type: 4,
        pip: {
          name: 'type',
          value: this.getTypeList()
        }
      },
      {
        field: 'kind',
        text: '所属类别'
      },
      {
        field: 'description',
        text: '问题描述',
        type: 5
      },
      {
        field: 'detailOption',
        text: '题目选项'
      },
      {
        field: 'answer',
        text: '题目答案'
      },
      {
        field: 'score',
        text: '问题分值'
      },
      {
        field: 'level',
        text: '难度等级'
      },
      {
        field: 'createTime',
        text: '创建时间',
        type: 4,
        pip: {
          name: 'date',
          value: 'yyyy-MM-dd HH:mm:ss'
        }
      },
      {
        text: '操作',
        type: 2
      }
    ];
  }

  /**
   * 获取列表数据
   * @param pageIndex
   * @param pageSize
   * @returns {Promise<any>}
   */
  getQuestionList(searchParams: any) {
    return new Promise((resolve, reject) => {
      this.http.get('http://www.easy-mock.com/mock/5a166a10d8031f24f9a782be/tester/api/management/question', searchParams)
        .subscribe(result => {
          resolve(result);
        });
    });
  }

  getKindList() {
    return new Promise((resolve, reject) => {
      this.http.get(`${this.http.SERVER_URL}questionKind`).subscribe((response: ResponseModel) => {
        if (response.result === '00000000') {
          resolve(response.data);
        } else {
          //reject(result);
        }
      });
    });
  }

  getLevelList() {
    return [
      {value: 1, label: '一'},
      {value: 2, label: '二'},
      {value: 3, label: '三'},
      {value: 4, label: '四'},
      {value: 5, label: '五'}
    ];
  }

  getTypeList() {
    return [
      {value: 0, label: '单选题'},
      {value: 1, label: '多选题'},
      {value: 2, label: '简答题'}
    ];
  }
}
